from recruit.models import Enterprise, Recruit
from rest_framework import serializers

class EnterpriseSimpleSerializer(serializers.ModelSerializer):
    """企业模型类序列化器 部分字段"""

    recruits = serializers.PrimaryKeyRelatedField(queryset=Recruit.objects.all(),many=True)  # queryset or read_only

    class Meta:
        model = Enterprise
        fields = ['id', 'name', 'labels', 'logo', 'summary', 'recruits']
#
#
class RecruitSimpleSerializer(serializers.ModelSerializer):
    """推荐职位模块 模型类序列化器"""

    enterprise = EnterpriseSimpleSerializer(read_only=True)

    class Meta:
        model = Recruit
        # exclude = ['address','state','detailcontent','detailrequire','visits','users']
        fields = ['id', 'jobname', 'salary', 'condition', 'education', 'type', 'city', 'createtime',
                  'enterprise', 'labels',
                  ]

class EnterpriseModelSerializer(serializers.ModelSerializer):
    """企业 模型类序列化器"""

    users = serializers.StringRelatedField(many=True)
    recruits = RecruitSimpleSerializer(many=True)

    class Meta:
        model = Enterprise
        fields = '__all__'


class RecruitModelSerializer(serializers.ModelSerializer):

    users = serializers.StringRelatedField(many=True)
    enterprise = EnterpriseModelSerializer(read_only=True)

    class Meta:
        model = Recruit
        fields = '__all__'
